// C_TCPAnswer.cpp: implementation of the C_TCPAnswer class.
//
//////////////////////////////////////////////////////////////////////

#include "C_TCPAnswer.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

C_TCPAnswer::C_TCPAnswer():C_Thread(0)
{
	m_pSocket = NULL;
	iStopNow = FALSE;
	m_pManager = NULL;
}

C_TCPAnswer::~C_TCPAnswer()
{

}

int C_TCPAnswer::Init(C_Socket *pSocket, I_Manager *pManager,char* pServerIP,char* pServerPort)
{
	if (pSocket == NULL || pManager == NULL)
	{
		Log("Error","C_TCPAnswer::Init","Input is Null");
		return -1;
	}
	m_pManager = pManager;
	m_pSocket = pSocket;
	strcpy(m_ServerIP,pServerIP);
	strcpy(m_ServerPort,pServerPort);
	return 1;
}


void C_TCPAnswer::DoWork()
{

	unsigned char cbuff[MAX_DATA_BUFFER];


	int iRet = 1;

	while(iStopNow != TRUE && iRet != SOCKET_ERROR)
			{
			iRet = 	m_pSocket->Recv(NULL,(char*)cbuff,MAX_DATA_BUFFER,0);
				
				if(iRet != 0)
				{
				m_pManager->PutData(cbuff,iRet,m_ServerIP,m_ServerPort);
				}
			}

		


}


void C_TCPAnswer::InitWork()
{
   
	
	Log("Info","C_TCPAnswer::InitWork","The listener thread is being created");

	iStopNow = false;

}

void C_TCPAnswer::StopWork()
{
    Log("Info","C_TCPAnswer::StopWork","The listener thread is being stopped");
	iStopNow = true;
}

void C_TCPAnswer::CleanWork()
{
    Log("Info","C_TCPAnswer::CleanWork","The listener thread is  stopped");
	iStopNow = true;
}

